package linked_list;

public class 删除链表节点 {
    class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }

    class Solution {
        public ListNode deleteNode(ListNode head, int val) {
            if(head.val == val)
                return head.next;
            ListNode pre = head;
            ListNode cur = head.next;
            while(cur != null && cur.val != val){
                pre = cur;
                cur = cur.next;
            }
            if(cur !=null)
                pre.next=cur.next;
            return head;
        }
    }
}
